package com.ruoyi.jproom.service.impl;

import com.ruoyi.jproom.entity.Residential;
import com.ruoyi.jproom.mapper.HousingEntrustMapper;
import com.ruoyi.jproom.mapper.ResidentialMapper;
import com.ruoyi.jproom.mapper.SellMapper;
import com.ruoyi.jproom.service.ImageInfoService;
import com.ruoyi.jproom.service.ResidentialService;
import com.ruoyi.jproom.utils.BaseResult;
import com.ruoyi.jproom.utils.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zeo
 * @explain 小区信息服务实现类
 * @date 2020/7/27 10:46
 */
@Service
public class ResidentialServiceImpl implements ResidentialService {

    @Autowired
    ResidentialMapper residentialMapper;

    @Autowired
    HousingEntrustMapper housingEntrustMapper;

    @Autowired
    SellMapper sellMapper;

    @Autowired
    ImageInfoService imageInfoService;


    @Override
    public BaseResult findResidentList(Residential residential) {
        List<Residential> residentials = residentialMapper.findResidentList(residential);
        if (residentials.size() == 0) {
            return BaseResult.build(ResultEnum.SELECT_NULL);
        } else {
            return BaseResult.build(ResultEnum.SUCCESS, residentials);
        }
    }

    @Override
    public String findResidentialIdByResidentialName(String name) {
        return residentialMapper.findResidentialIdByResidentialName(name);
    }

    @Override
    public Residential findResidentByResidentialId(String residentialId) {
        Residential residential = residentialMapper.findResidentByResidentialId(residentialId);
        residential.setImageInfoList(imageInfoService.findImageInfoListBySellId(residentialId));
        return residential;
    }

    @Override
    public List<Residential> serverFindResidentList(Residential residential) {
        return residentialMapper.findResidentList(residential);
    }

    @Override
    public int rentResidentialEdit(Residential residential) {
        return residentialMapper.rentResidentialEdit(residential);
    }
}
